import {MenuInfo, MenuInterface} from '@/types/interface/menu.interface';


export const searchRoute = (param: MenuInfo, menuList: Array<MenuInterface> = []): MenuInterface | null => {
    let result = null;
    menuList.forEach((item) => {
        if (item.key === param.key) {
            result = item;
            return;
        }
        if (item.children) {
            let res = searchRoute(param, item.children);
            if (res) {
                result = res;
            }
        }
    });
    return result;
};
/**
 * @description 获取需要展开的 subMenu
 * @param {String} path 当前访问地址
 * @returns array
 */
export const getOpenKeys = (path: string) => {
    let newStr: string = '';
    let newArr: any[] = [];
    let arr = path.split('/').map(i => '/' + i);
    for (let i = 1; i < arr.length - 1; i++) {
        newStr += arr[i];
        newArr.push(newStr);
    }
    return newArr;
};
